/*            Copyright(c) 2006-2008 Dave Sexton           *
 * http://www.codeplex.com/DocProject                      *
 * http://www.codeplex.com/DocProject/Project/License.aspx *
 ***********************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;

namespace DaveSexton.DocProject.Sandcastle.BuildComponents
{
	public class SandcastleBuildComponentManagerTypeConverter : SortedPropertyConverter
	{
		#region Public Properties
		#endregion

		#region Private / Protected
		#endregion

		#region Constructors
		/// <summary>
		/// Constructs a new instance of the <see cref="SandcastleBuildComponentManagerTypeConverter" /> class.
		/// </summary>
		public SandcastleBuildComponentManagerTypeConverter()
		{
		}
		#endregion

		#region Methods
		public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes)
		{
			SandcastleBuildComponentManager manager = (SandcastleBuildComponentManager) value;

			manager.EnsureLoaded();

			PropertyDescriptorCollection properties = new PropertyDescriptorCollection(null);

			if (manager.ShowEntireBuildComponentStack)
				foreach (SandcastleBuildComponent component in manager.Components)
					properties.Add(new SandcastleBuildComponentPropertyDescriptor(manager, component));
			else
				foreach (SandcastleBuildComponent component in manager.Components)
					if (component.CanDisplayOrEdit(context))
						properties.Add(new SandcastleBuildComponentPropertyDescriptor(manager, component));

			return Sort(properties);
		}

		protected override int GetPropertySortIndex(MemberDescriptor member)
		{
			return ((SandcastleBuildComponentPropertyDescriptor) member).ComponentIndex;
		}
		#endregion
	}
}
